<?php

/**
 * LrArticle filter form base class.
 *
 * @package    Onnobostro
 * @subpackage filter
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormFilterGeneratedTemplate.php 24171 2009-11-19 16:37:50Z Kris.Wallsmith $
 */
abstract class BaseLrArticleFormFilter extends BaseFormFilterDoctrine
{
  public function setup()
  {
    $this->setWidgets(array(
      'image'                     => new sfWidgetFormDoctrineChoice(array('model' => 'DmMedia', 'add_empty' => true)),
      'author'                    => new sfWidgetFormDoctrineChoice(array('model' => 'DmUser', 'add_empty' => true)),
      'newsletter'                => new sfWidgetFormDoctrineChoice(array('model' => 'LrNewsletter', 'add_empty' => true)),
      'is_active'                 => new sfWidgetFormChoice(array('choices' => array('' => $this->getI18n()->__('yes or no', array(), 'dm'), 1 => $this->getI18n()->__('yes', array(), 'dm'), 0 => $this->getI18n()->__('no', array(), 'dm')))),
      'position'                  => new sfWidgetFormDmFilterInput(),
      'related_product_list_list' => new sfWidgetFormDoctrineChoice(array('multiple' => true, 'model' => 'Product')),
    ));

    $this->setValidators(array(
      'image'                     => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Image'), 'column' => 'id')),
      'author'                    => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Author'), 'column' => 'id')),
      'newsletter'                => new sfValidatorDoctrineChoice(array('required' => false, 'model' => $this->getRelatedModelName('Newsletter'), 'column' => 'id')),
      'is_active'                 => new sfValidatorChoice(array('required' => false, 'choices' => array('', 1, 0))),
      'position'                  => new sfValidatorSchemaFilter('text', new sfValidatorInteger(array('required' => false))),
      'related_product_list_list' => new sfValidatorDoctrineChoice(array('multiple' => true, 'model' => 'Product', 'required' => false)),
    ));
    
    $this->mergeI18nForm();


    $this->widgetSchema->setNameFormat('lr_article_filters[%s]');

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);

    $this->setupInheritance();

    parent::setup();
  }

  public function addRelatedProductListListColumnQuery(Doctrine_Query $query, $field, $values)
  {
    if (!is_array($values))
    {
      $values = array($values);
    }

    if (!count($values))
    {
      return;
    }

    $query->leftJoin('r.RelatedArticleProduct RelatedArticleProduct')
          ->andWhereIn('RelatedArticleProduct.product_id', $values);
  }

  public function getModelName()
  {
    return 'LrArticle';
  }

  public function getFields()
  {
    return array(
      'id'                        => 'Number',
      'image'                     => 'ForeignKey',
      'author'                    => 'ForeignKey',
      'newsletter'                => 'ForeignKey',
      'is_active'                 => 'Boolean',
      'position'                  => 'Number',
      'id'                        => 'Number',
      'title'                     => 'Text',
      'summary'                   => 'Text',
      'body'                      => 'Text',
      'lang'                      => 'Text',
      'created_at'                => 'Date',
      'updated_at'                => 'Date',
      'related_product_list_list' => 'ManyKey',
    );
  }
}
